from rest_framework.views import exception_handler


def custom_exception_handler(exc, context):
    response = exception_handler(exc, context)

    if response is not None:
        response.data['errCode'] = response.status_code
        try:
            response.data['errMsg'] = response.data[list(response.data.keys())[0]][0]
            # del response.data[list(response.data.keys())[0]]
            response.data['data'] = {}
        except KeyError:
            response.data['errMsg'] = 'Internel Error'
            response.data['data'] = {}
    return response
